//
//  MineShareTableViewController.m
//  MJApp
//
//  Created by wangliang on 15/3/30.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "MineShareTableViewController.h"
#import "MineShareTableViewCell.h"
#import "ProductInfoViewController.h"
@interface MineShareTableViewController ()<HomeCellDelegate>

@property(nonatomic,strong)NSMutableArray *shareList;

@end

@implementation MineShareTableViewController

- (NSMutableArray *)shareList {
    
    if (!_shareList) {
        _shareList = [NSMutableArray array];
    }
    return _shareList;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self UI];
}

- (void)UI {
    
    self.title = @"我的分享";
    self.tableView.separatorColor = [UIColor clearColor];
    self.tableView.backgroundColor = Color_Back_Black;
    [self obationData];
}

- (void)obationData {
    
    NSDictionary *dic = @{@"user_id":[userInfoTool share].ID};
    [WLHttpRequestAfter userGetMyShareWithParam:dic usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
        
        [self.shareList removeAllObjects];
        [self.shareList addObjectsFromArray:resultDictionary[@"data"]];
        [self.tableView reloadData];
        
    } andFailureBlock:^(NSError *resultError) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.shareList.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MineShareTableViewCell *cell = (MineShareTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.cellHigh;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   
    MineShareTableViewCell *cell = [MineShareTableViewCell initWithTableView:tableView];
    cell.infoDic = self.shareList[indexPath.row];
    cell.delegte = self;
    return cell;
}

- (void)homeCell:(id)cell withInfo:(id)info {
    
    
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"id"] = info[@"id"];
    
    [WLHTTPRequest getGoodsDeatailWithParam:param usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
        
        ProductInfoViewController * product = [[ProductInfoViewController alloc] init];
        product.detailDic = resultDictionary[@"data"];
        [self.navigationController pushViewController:product animated:YES];
    } andFailureBlock:^(NSError *resultError) {
        
    }];

}



@end
